package com.fifth.apartment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fifth.apartment.entity.Housekeeper;
import com.fifth.apartment.mapper.HousekeeperMapper;
import com.fifth.apartment.service.HousekeeperService;
import com.fifth.apartment.vo.PageQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-07-09
 */
@Service
public class HousekeeperServiceImpl extends ServiceImpl<HousekeeperMapper, Housekeeper> implements HousekeeperService {
@Autowired
    private HousekeeperMapper housekeeperMapper;

    @Transactional(readOnly = true)
    @Override
    public Page<Housekeeper> findPage(PageQueryVO vo) {
        Integer currentPage = vo.getCurrentPage();
        Integer pageSize = vo.getPageSize();
        Page<Housekeeper> page = new Page<>(currentPage , pageSize);

        String queryString = vo.getQueryString();
        LambdaQueryWrapper<Housekeeper> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StringUtils.hasLength(queryString) , Housekeeper::getPersonId , queryString)
                .or()
                .like(StringUtils.hasLength(queryString) , Housekeeper::getHousekeeper , queryString)
                .or()
                .eq(StringUtils.hasLength(queryString) ,Housekeeper::getEntryApartment , queryString);
        Page<Housekeeper> housekeeperPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
        return housekeeperPage;
    }
}
